      SUBROUTINE ANGPLT
      IMPLICIT REAL*8 (A-H,O-Z)
      REAL*8 PI/ 3.141592653589793D0 /
C
C  THIS ROUTINE IS THE INTERFACE BETWEEN CHARLIE PETRUZZO'S ANGLE
C  PLOT ROUTINES AND THE CALLER.
C
C
C
C  --------------- ANGPL1 / ANGPL2 / ANGPL3 ---------------------------
C
C  THIS ROUTINE AND ENTRY POINTS ARE USED TO PRODUCE PRINTER PLOTS
C  OF ANGLE QUANTITIES( EX- RACN/DECL, EL/AZ,...). THE PLOT IS 
C  ALWAYS 180x360 DEGREES. 
C 
C  USAGE----  1) CALL ANGPL1 ONCE TO INTIALIZE SYMHLD AND INTERNAL
C                VARIABLES.
C             2) CALL ANGPL2 MANY TIMES TO PLACE ANGLE PAIRS ON THE
C                GRID. ONE CALL FOR EACH PAIR PLACED.
C             3) CALL ANGPL3 TO PRINT THE GRID.
C
C
C
C//////////////////////////////////////////////////////////////////////
C
C     STANDARD ARRAYS FOR PETRUZZO'S PRINTER PLOT ROUTINES FOR ANGLES.
C
      LOGICAL*1 SYMHLD(61,121)
      REAL*4 PLTPRM(19)
      INTEGER BOTTOM,RIGHT
      REAL*8 XSEG,YSEG,WEST,SHIFT,DX,DY
C
CCC   EQUIVALENCE (PLTPRM(1),XSEG),(PLTPRM(3),YSEG),
CCC  1            (PLTPRM(5),WEST),(PLTPRM(7),SHIFT),
CCC  2            (PLTPRM(9),DX  ),(PLTPRM(11),DY  )
CCC   EQUIVALENCE (PLTPRM(13),BOTTOM),(PLTPRM(14),RIGHT),
CCC  1            (PLTPRM(15),IEWLBL),(PLTPRM(16),ILABEL),
CCC  2            (PLTPRM(17),IGRID ),(PLTPRM(18),IEQATR),
CCC  3            (PLTPRM(19),IOPTN )
C
C     SHORT DESCRIPTION(ANGPLT HAS A LONGER DESCRIPTION)----------
C
C     USER MUST SET THE VARIABLES AS NAMED BELOW. DO NOT SET PLTPRM
C     DIRECTLY. (EX- USE BOTTOM=19, NOT PLTPRM(13)=19.)
C
C  1,2     XSEG(R*8)   RADIANS BETWEEN TICK MARKS FOR X-AXIS.
C  3,4     YSEG(R*8)   RADIANS BETWEEN TICK MARKS FOR Y-AXIS.
C  5,6     WEST(R*8)   ANGLE VALUE OF LEFT HAND BORDER. RADIANS.
C  7,8     SHIFT(R*8)  NOT USER-DEFINED.
C  9,10    DX(R*8)     NOT USER-DEFINED.
C  11,12   DY(R*8)     NOT USER-DEFINED.
C  13      BOTTOM(I*4) NUMBER OF LINES IN THE PRINTER PLOT.
C  14      RIGHT(I*4)  NUMBER OF COLUMNS IN THE PRINTER PLOT.
C  15      IEWLBL(I*4) EAST ONLY(+1)/EAST&WEST(-1) FLAG FOR LABELS.
C  16      ILABEL(I*4) YES(1)/NO(0) FLAG FOR LABELS.
C  17      IGRID(I*4)  YES(1)/NO(0) FLAG FOR GRID LINES AT TICK MARK.
C  18      IEQATR(I*4) YES(1)/NO(0) FLAG FOR EQUATOR INDICATION.
C  19      IOPTN(I*4)  MAP OPTION. 1=RECTANGULAR, 2=AITOFF.
C
C/////////////////////////////////////////////////////////////////////
C
C
C*********************************************************
C
C   CODED BY CHARLIE PETRUZZO   2/81.
C
C   MODIFIED....
C       CJP 4/81  ADDED PLTPRM. 
C       CJP 6/81  ADDED COMMENTS AND CHECKS ON BOTTOM AND RIGHT VALUES.
C       CJP 5/82  ADDED COMMENTS. NO CODE CHANGED.
C
C +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +
C
      REAL*4 R4IOPT,R4BOTT,R4RGHT
      EQUIVALENCE (R4IOPT,IOPTN),(R4BOTT,BOTTOM),(R4RGHT,RIGHT)
C
C +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
C
C
C                           **********
C                           *        *
C  ************************ * ANGPL1 * ********************************
C                           *        *
C                           **********
C
C  THIS ROUTINE SETS UP A GRID FOR SUBSEQUENT USE IN
C  CREATING PRINTER PLOTS OF QUANTITIES EXPRESSED IN
C  LAT/LONG, DECL/RACN, EL/AZ,.....
C
C  THE SYMHLD ARRAY IS RETURNED TO THE CALLER READY TO HAVE 
C  ELEMENTS FILLED SHOWING THE LOCATION ON THE GRID OF THE
C  QUANTITIES PLOTTED.
C
C * * * * * * * * * *  CALLING SEQUENCE INFO * * * * * * * * * * *
C
C  INPUT --  PLTPRM(1-6,13-19) ARE INPUT. THE VARIABLES BELOW ARE SET BY
C            THE USER AND THE EQUIVALENCE STATEMENT IN THE CALLER'S
C            PROGRAM CAUSES THE PROPER VALUES TO BE SET IN PLTPRM. NOTE
C            THAT THE CALLING PROGRAM DOES NOT SET PLTPRM ELEMENTS 
C            DIRECTLY. FOR EXAMPLE, TO GET A PLOT WITH GRID LINES ON IT,
C            THE USER SETS IGRID=1; PLTPRM(17)=1.0 IS NOT USED.  
C            THE NAME PLTPRM NEVER IS FOUND ON THE LEFT SIDE OF THE
C            EQUAL SIGN IN THE CALLING PROGRAM.
C
C            IT IS MOST CONVENIENT FOR THE USER TO COPY THE SOURCE CODE
C            BETWEEN THE TWO LINES OF /'S ABOVE AND REMOVE THE 'CCC' 
C            FROM THE EQUIVALENCE STATEMENTS. THEN SET XSEG,...,IOPTN
C            AS REQUIRED.
C
C  OUTPUT -- PLTPRM(7-12) ARE OUTPUT. THESE ARE RE-ENTERED IN ANGPL2
C            AND ANGPL3 BELOW. THE PLTPRM ARRAY IS USED TO ALLOW
C            MORE THAN ONE PLOT TO BE GENERATED SIMULTANEOUSLY. 
C            THAT IS, THERE MAY BE MULTIPLE SYMHLD ARRAYS AND THEIR
C            CORRESPONDING PLTPRM ARRAYS. ALL SYMHLD ARRAYS MAY BE
C            INITIALIZED, FILLED, AND PRINTED IN PARALLEL, RATHER
C            THAN EACH INITIALIZED, FILLED AND PRINTED BEFORE ANOTHER
C            IS STARTED.
C
C   *** NOTE *** 
C
C       AFTER ANGPL1 HAS RETURNED, NO CHANGES TO PLTPRM ARE PERMITTED
C       UNTIL THE PLOT IS PRINTED OR ABANDONED. 
C
C
C                ALL ANGLE QUANTITIES ARE IN RADIANS.
C
C  VARIABLE    DIM  TYPE    DESCRIPTION
C  --------    ---  ----    -----------
C
C  SYMHLD     61,121  L*1   THIS ARRAY IS USED TO HOLD 
C                           CHARACTERS THAT FORM A GRID AND
C                           CAN BE PRINTED LATER.
C
C  BOTTOM      1    I4      THIS GIVES THE NUMBER OF LINES
C                           USED TO FORM THE GRID. A CRT
C                           TERMINAL REQUIRES FEWER
C                           LINES TO FILL IT THAN A LINE
C                           PRINTER NEEDS TO FILL A PAGE.
C
C                           MAX VALUE FOR BOTTOM IS 61.
C
C  RIGHT       1    I4      THIS GIVES THE NUMBER OF PRINT
C                           POSITIONS USED TO FORM THE GRID.
C                           A CRT TERMINAL WOULD NEED FEWER
C                           TO FILL THE SCREEN THAN A LINE
C                           PRINTER NEEDS TO FILL A PAGE.
C
C                           MAX VALUE FOR RIGHT IS 121.
C
C  XSEG        1    R8      THIS IS THE NUMBER OF RADIANS
C                           BETWEEN MERIDIAN LINES. USE 
C                           TWOPI TO GET NO MERIDIANS.
C                           SEE NOTE BELOW.
C
C  YSEG        1    R8      THIS IS THE NUMBER OF RADIANS
C                           BETWEEN PARALLELS. USE PI
C                           TO GET NO PARALLELS.
C                           SEE NOTE BELOW.
C
C  IEWLBL      1    I4      THIS IS A FLAG USED TO TELL
C                           THE ROUTINE WHETHER TO LABEL LONGI- 
C                           TUDES AS EAST AND WEST OR ALL EAST.
C                           =-1 MEANS LABEL EAST AND WEST 
C                           =+1 MEANS LABEL ALL AS EAST.
C
C  ILABEL      1    I4      FLAG TELLING THE ROUTINE WHETHER TO PUT 
C                           LABELS ON THE GRID EVERY XSEG/YSEG
C                           INTERVALS TO SHOW THE ANGLE VALUE
C                           AT THAT MERIDIAN OR PARALLEL.
C                           =1 MEANS LABELS
C                           =0 MEANS NO LABELS.
C
C  IGRID       1    I4      FLAG TELLING THE PROGRAM WHETHER TO DRAW
C                           VERTICAL AND HORIZONTAL GRID LINES 
C                           AT XSEG/YSEG INTERVALS.
C                           =0 MEANS NO GRID
C                           =1 MEANS GRID
C
C  IEQATR      1    I4      FLAG TELLING THE PROGRAM WHETHER TO
C                           MARK THE EQUATOR WITH 'E' CHARACTER.
C                           =1 MARK IT
C                           =0 DO NOT MARK IT
C
C  WEST        1    R8      THIS IS THE WEST BORDER VALUE. 
C                           IF WEST IS ENTERED AS, SAY, 
C                           -100/DEGRAD, THEN THE WEST BORDER IS
C                           LABELED 100W IF IEWFLG IS -1.  
C                           IT IS LABELED 260E IF IEWFLG IS +1.
C
C  IOPTN       1    I4      THIS INDICATES THE TYPE OF GRID ON WHICH
C                           THE PLOT IS GIVEN. 
C                           =1 MEANS RECTANGULAR GRID.
C                           =2 MEANS AITOFF GRID.
C
C
C  NOTE -- IN ORDER FOR PROPER CONSTRUCTION OF THE GRID, THE USER
C          MUST BE SURE THAT YSEG AND BOTTOM CORRESPOND SUCH THAT
C          YSEG CAN BE EVENLY DIVIDED BY PI/(BOTTOM-1). FOR
C          EXAMPLE, BOTTOM=19 AND YSEG=45./DEGRAD DO NOT CORRESPOND
C          BECAUSE EACH ROW OF SYMHLD IS 10./DEGRAD WIDE, WHILE THE
C          USER WANTS TICK MARKS EVERY 45./DEGRAD. SIMILARLY,
C          XSEG MUST BE EVENLY DIVIDED BY TWOPI/(RIGHT-1).
C
C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C
C     INITIALIZATION OF SYMHLD AND PART OF PLTPRM.
C
      ENTRY ANGPL1(SYMHLD,PLTPRM)
C
      R4IOPT=PLTPRM(19)
      R4BOTT=PLTPRM(13)
      R4RGHT=PLTPRM(14)
      IF(BOTTOM.LT.2 .OR. BOTTOM.GT.61) RETURN
      IF(RIGHT.LT.2 .OR. RIGHT.GT.121) RETURN
C
      IF(IOPTN.EQ.1) CALL SETGRD(SYMHLD,PLTPRM)
      IF(IOPTN.EQ.2) CALL SETAIT(SYMHLD,PLTPRM)
      RETURN
C
C
C                           **********
C                           *        *
C  ************************ * ANGPL2 * ********************************
C                           *        *
C                           **********
C
C     THIS CODE PLACES THE ANGLE PAIR ANG1/ANG2 IN ITS PROPER LOCATION
C     IN SYMHLD. ANGPL1 MUST BE CALLED BEFORE CALLING ANGPL2.
C
C  VARIABLES----     ANG1, ANG2, PLTPRM, SYMBOL ARE ARE INPUT.
C                    SYMHLD IS INPUT AND OUTPUT.
C
C  VARIABLE  DIM  TYPE    DESCRIPTION
C  --------  ---  ----    -----------
C
C  ANG1      1    R8     FIRST ANGLE IN THE ANGLE PAIR. RADIANS.
C                         EX- LAT IN A LAT/LONG PAIR, EL IN AN EL/AZ
C                             PAIR, DECL IN A DECL/RACN PAIR.
C
C  ANG2      1    R8     SECOND ANGLE IN THE PAIR. RADIANS.
C
C  SYMHLD  61,121 L*1    THE SAME ARRAY THAT WAS USED TO CALL ANGPL1.
C
C  PLTPRM   13    R*4    THE SAME ARRAY THAT WAS USED TO CALL ANGPL1.
C
C  SYMBOL    1    L*1    THE SYMBOL TO BE USED TO SHOW THE LOCATION
C                        ON THE GRID OF THE ANG1,ANG2 PAIR.
C
      ENTRY ANGPL2(ANG1,ANG2,SYMHLD,PLTPRM,SYMBOL)
C
C     PLACEMENT OF PLOT SYMBOL IN PROPER LOCATION IN SYMHLD.
C
C
      R4IOPT=PLTPRM(19)
      R4BOTT=PLTPRM(13)
      R4RGHT=PLTPRM(14)
      IF(BOTTOM.LT.2 .OR. BOTTOM.GT.61) RETURN
      IF(RIGHT.LT.2 .OR. RIGHT.GT.121) RETURN
      IF(DABS(ANG1).GT.PI) RETURN
C
      IF(IOPTN.EQ.1) CALL LOCGRD(ANG1,ANG2,SYMHLD,PLTPRM,SYMBOL) !SETGRD
      IF(IOPTN.EQ.2) CALL AITLOC(ANG1,ANG2,SYMHLD,PLTPRM,SYMBOL) !SETAIT
      RETURN
C
C
C                           **********
C                           *        *
C  ************************ * ANGPL3 * ********************************
C                           *        *
C                           **********
C
C     THIS CODE PRINTS THE GRID. 
C
C  VARIABLES    DIM    TYPE     DESCRIPTION
C  _________    ___    ____     ___________
C
C  SYMHLD       61,121  L*1     THE SAME AS ANGPL1 AND ANGPL2.
C
C  PLTPRM       13      R*4     THE SAME AS ANGPL1 AND ANGPL2.
C
C  IPRINT       1      I*4      THE FORTRAN UNIT FOR PRINTING.
C
      ENTRY ANGPL3(SYMHLD,PLTPRM,IPRINT)
C
C     PRINT THE PLOT.
C
      R4IOPT=PLTPRM(19)
      R4BOTT=PLTPRM(13)
      R4RGHT=PLTPRM(14)
      IERR=0
      IF(BOTTOM.LT.2 .OR. BOTTOM.GT.61) IERR=1
      IF(RIGHT.LT.2 .OR. RIGHT.GT.121) IERR=1
      IF(IOPTN.LT.1 .OR. IOPTN.GT.2) IERR=1
C
      IF(IERR.EQ.0) GO TO 100
      WRITE(IPRINT,150) BOTTOM,RIGHT,IOPTN
  150 FORMAT(///,' PLOT NOT PRINTED BECAUSE OF INVALID VALUES',
     1    ' FOR ONE OF THE FOLLOWING....'/,
     2    ' BOTTOM=',I4,'  (MIN=2,MAX=61)'/,
     3    ' RIGHT= ',I4,'  (MIN=2,MAX=121)'/,
     4    ' IOPTN= ',I4,'  (=1, OR =2. NO OTHER IS VALID.)'//)
      RETURN
C
  100 CONTINUE
      IF(IOPTN.EQ.1) CALL PRTGRD(SYMHLD,PLTPRM,IPRINT) ! ENTRY IN SETGRD
      IF(IOPTN.EQ.2) CALL PRTAIT(SYMHLD,PLTPRM,IPRINT) ! ENTRY IN SETAIT
      RETURN
C
C
      END
